From 886cbf679e41cf23509131ad79119a664e40f608 Mon Sep 17 00:00:00 2001
From: rofl0r <retnyg@gmx.net>
Date: Thu, 2 Aug 2012 09:25:37 +0200
Subject: [PATCH] cumulative fix

---
 src/interface.c              |    8 +++---
 src/main.c                   |    4 +-
 src/types.h                  |    7 +++--
 src/xfce-taskmanager-linux.c |   57 ++++++++++++++++++++++++++++++++++-------
 4 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/src/interface.c b/src/interface.c
index 76c41e8..c68c00a 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -346,7 +346,7 @@ GtkWidget* create_mainmenu (void)
     gtk_widget_show(preferences1);
     gtk_menu_shell_append(GTK_MENU_SHELL(mainmenu), preferences1);
 
-    g_signal_connect ((gpointer) show_user_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)own_uid);
+    g_signal_connect ((gpointer) show_user_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *) (size_t) own_uid);
     g_signal_connect ((gpointer) show_root_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)0);
     g_signal_connect ((gpointer) show_other_tasks1, "toggled", G_CALLBACK (on_show_tasks_toggled), (void *)-1);
     g_signal_connect ((gpointer) show_cached_as_free1, "toggled", G_CALLBACK (on_show_cached_as_free_toggled), (void *)0);
@@ -422,11 +422,11 @@ void fill_list_item(gint i, GtkTreeIter *iter)
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_PPID, buf, -1);
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_STATE, task->state, -1);
 
-        /* size */
-        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_MEM, size_to_string(buf, task->size * 1024), -1);
+        /* vm size */
+        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_MEM, size_to_string(buf, task->size), -1);
 
         /* rss */
-        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_RSS, size_to_string(buf, task->rss*1024), -1);
+        gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_RSS, size_to_string(buf, task->rss), -1);
 
         gtk_tree_store_set(GTK_TREE_STORE(list_store), iter, COLUMN_UNAME, task->uname, -1);
         sprintf(buf,"%0d%%", (guint)task->time_percentage);
diff --git a/src/main.c b/src/main.c
index 2fbe20b..8ed4489 100644
--- a/src/main.c
+++ b/src/main.c
@@ -56,7 +56,7 @@ guint win_height;
 guint refresh_interval;
 guint rID;
 
-int PAGE_SIZE;
+int page_size;
 
 int main (int argc, char *argv[])
 {
@@ -72,7 +72,7 @@ int main (int argc, char *argv[])
 #endif
     gtk_init (&argc, &argv);
 
-    PAGE_SIZE=sysconf(_SC_PAGESIZE)>>10;
+    page_size = sysconf(_SC_PAGESIZE);
     own_uid = getuid();
 
     config_file = g_build_filename(g_get_user_config_dir(), "lxtask.conf", NULL);
diff --git a/src/types.h b/src/types.h
index 7a9e812..d57567e 100644
--- a/src/types.h
+++ b/src/types.h
@@ -21,6 +21,7 @@
 #define TYPES_H
 
 #include <gtk/gtk.h>
+#include <stddef.h>
 
 #define REFRESH_INTERVAL 1000
 
@@ -32,8 +33,8 @@ struct task
     gchar uname[64];
     gchar name[64];
     gchar state[16];
-    gint size;
-    gint rss;
+    size_t size;
+    size_t rss;
     gboolean checked;
     gint time;
     gint old_time;
@@ -79,6 +80,6 @@ extern guint win_height;
 const gchar *custom_signal_0;
 const gchar *custom_signal_1;
 
-extern int PAGE_SIZE;
+extern int page_size;
 
 #endif
diff --git a/src/xfce-taskmanager-linux.c b/src/xfce-taskmanager-linux.c
index 858ea30..e7923e5 100644
--- a/src/xfce-taskmanager-linux.c
+++ b/src/xfce-taskmanager-linux.c
@@ -35,6 +35,7 @@ void get_task_details(gint pid,struct task *task)
 {
 	int fd;
 	gchar line[256];
+	ssize_t ret;
 
 	task->pid=-1;
 	task->checked=FALSE;
@@ -43,12 +44,13 @@ void get_task_details(gint pid,struct task *task)
 	sprintf(line,"/proc/%d/statm",pid);
         fd=open(line,O_RDONLY);
         if(fd==-1) return;
-        read(fd,line,256);
-        sscanf(line,"%d %d",&task->size,&task->rss);
-        close(fd);
-        if(!task->size) return;
-	task->size*=PAGE_SIZE;
-	task->rss*=PAGE_SIZE;
+        ret = read(fd,line,sizeof(line));
+	if(!ret || ret == -1) goto err;
+	sscanf(line,"%zu %zu",&task->size,&task->rss);
+	close(fd);
+	if(!task->size) return;
+	task->size *= page_size;
+	task->rss *= page_size;
 
 	sprintf(line,"/proc/%d/stat",pid);
 	fd=open(line,O_RDONLY);
@@ -63,11 +65,46 @@ void get_task_details(gint pid,struct task *task)
 
 		task->pid=pid;
 		
-		read(fd,buf,2048);
-		p=strchr(buf,'(');p++;
+		ret = read(fd,buf,sizeof(buf));
+		if(!ret || ret == -1) {
+			err:
+			close(fd);
+			return;
+		}
+
+		p=strchr(buf,'(');
+		if(!p) goto err;
+		p++;
 		for(len=0;*p!=')';len++) task->name[len]=*p++;
-		task->name[len]=0;p++;
-		if(len>=15)
+		task->name[len]=0;
+		p++;
+		if(0)
+		{
+			FILE *fp;
+			sprintf(line,"/proc/%d/cmdline",pid);
+			fp=fopen(line,"r");
+			if(fp)
+			{
+				size_t size;
+				size=fread(task->name,1,sizeof(task->name)-1,fp);
+				if(size>0)
+				{
+					int i;
+					task->name[size]=0;
+					for(i=0;i<size;i++)
+					{
+						if(task->name[i]=='\0')
+						{
+							if(task->name[i+1]=='\n')
+								break;
+							task->name[i]=' ';
+						}
+					}
+				}
+				fclose(fp);
+			}
+		}
+		else if(len>=15)
 		{
 			FILE *fp;
 			sprintf(line,"/proc/%d/cmdline",pid);
-- 
1.7.3.4

